package ua.epam.muzalevskiy.traction.commands;

import java.io.IOException;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import ua.epam.muzalevskiy.traction.configuretion.MessageConfigurer;
import ua.epam.muzalevskiy.traction.configuretion.PagePathConfigurer;
import ua.epam.muzalevskiy.traction.configuretion.PageViewConfigurer;
import ua.epam.muzalevskiy.traction.configuretion.LocaleHelper;

/**
 * <code>ChangeLocaleToEnCommand</code> class is the <code>Command</code> interface
 * implementation. This command realizes changing application language in 
 * accordance with specified locale. The execution of this command changes
 * current locale to en.
 *
 * @author Muzalevskiy Vitaliy
 */
public class ChangeLocaleToEnCommand implements Command{
    
    private static Logger logger = Logger.getLogger(ChangeLocaleToEnCommand.class);

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Locale locale = new Locale("en");       
        //changes locale for web application
        PageViewConfigurer.ChangeLocale(locale);
        MessageConfigurer.ChangeLocale(locale);
        LocaleHelper.setViewValues(request);
        String page = PagePathConfigurer.getInstance()
                        .getProperty(PagePathConfigurer.INDEX_PAGE);
        return page;
    }
    
}
